package IOperation;

import Book.BookList;
import Book.book;

import java.util.Scanner;

public class deleteOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("删书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的书");
        String name = scanner.nextLine();
        int pos = 0;
        for (int i = 0; i < bookList.getBookSize(); i++) {
            if (bookList.getBook(i).getName().equals(name)) {
                pos = i;
                for (int j = pos; j < bookList.getBookSize() - 1; j++) {
                    book b = bookList.getBook(j + 1);
                    bookList.setBook(j, b);
                }
                System.out.println("删除成功");
                bookList.setBookSize(bookList.getBookSize() - 1);
               return ;
            }
        }
        System.out.println("没有找到");




    }
}
